/**
 * 缓存当前视图
 * @param storeName 文件名
 */
import { defineStore } from 'pinia'
import Cache from '@/global/Cache'
import * as CacheKey from '@/global/CacheKey'

export default defineStore('createView', {
  state: () => {
    return {
      createView: Cache.get(CacheKey.CREATE_VIEW,'')
    };
  },
  actions: {
    loadState() {
      const currentState = Cache.get(CacheKey.CREATE_VIEW, '')
      this.$patch({ createView: JSON.parse(currentState) });
    },
    saveState(newState: any) {
      this.createView = newState;
      Cache.save(CacheKey.CREATE_VIEW, newState);
    },
    getState(): any {
      return Cache.get(CacheKey.CREATE_VIEW, '');
    },
    resetState() {
      this.$reset();
    },
    clearState() {
      console.log('clearState');
      Cache.remove(CacheKey.CREATE_VIEW);
    }
  }
})